package com.nanhu.sms.widget;

import com.nanhu.sms.util.DensityUtil;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.EditText;

public class DashlineEditTextOne extends EditText{
	
	private static final String TAG = "DashlineEditTextOne";
	
	private int color;
	
	private float addition;
	
	public DashlineEditTextOne(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	public DashlineEditTextOne(Context context, AttributeSet attrs) {
        super(context, attrs);
        addition = DensityUtil.dip2px(context, 5);
        //第三个参数：如果属性不存在则要使用的默认值
//        int resourceId = attrs.getAttributeResourceValue(PACKAGE_NAME, "backgroud", Color.GREEN);
        //得到id对应的颜色值
//        color = getResources().getColor(resourceId);
        color = Color.GREEN;
   }

	@Override
	protected void onDraw(Canvas canvas) {
		int lineHeight =  this.getLineHeight();
		Paint mPaint = getPaint();
		mPaint.setColor(color);
		
		int topPadding = this.getPaddingTop();
		int leftPadding = this.getPaddingLeft();
		float textSize = this.getTextSize();
		setGravity(Gravity.LEFT|Gravity.TOP);
		int y = (int)(topPadding + textSize);
		int layoutHeight = this.getHeight() / lineHeight;
		int maxLineCount = Math.max(this.getLineCount(), layoutHeight);
		for(int i = 0; i < maxLineCount; i++){
			canvas.drawLine(leftPadding, y+addition, getRight() - leftPadding, y+addition, mPaint);
			y+=lineHeight;
		}
		canvas.translate(0, 0);
		super.onDraw(canvas);
	}
}
